﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Autofac.Configuration;
using Autofac.Core;
using Autofac.Builder;
using DemoAutofac.Models;

namespace LogBuilder {
    class XMLConfig {

        public void buildALog() {
            var builder = new ContainerBuilder();
            builder.RegisterModule(new ConfigurationSettingsReader("mycomponents"));
            
            builder.RegisterType(typeof(SQLLog)); //register a class
            
            
            using (var container = builder.Build()) {
                var mylog = container.Resolve<ILog>("weblog");
                mylog.log("Today it is sunny");

                var mysonlog = container.Resolve<ILog>("sqllog");
                mysonlog.log("Tomorrow it will rain");

                //Autowiring feature
                var mywifelog = container.Resolve<SQLLog>(new NamedParameter("connection", "UKServer"));
                mywifelog.log("Yesterday it was cloudy");

                SQLLog myfriendlog = container.Resolve<SQLLog>(new NamedParameter("level", 4));
                myfriendlog.log("I don't know weather forecast");
                
                Console.WriteLine("{0}", myfriendlog.GetType().ToString());

                if (myfriendlog is SQLLog) {
                    
                }
            }
        }
    }
    
}
